package com.yonyou.gmmc.service.shopping.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yonyou.gmmc.service.shopping.dao.TmFixCodeMapper;
import com.yonyou.gmmc.service.shopping.dao.TmTpProductCategoryMapper;
import com.yonyou.gmmc.service.shopping.dao.TmTpProductGroupMapper;
import com.yonyou.gmmc.service.shopping.model.TmFixCode;
import com.yonyou.gmmc.service.shopping.model.TmTpProductCategory;
import com.yonyou.gmmc.service.shopping.model.TmTpProductGroup;

@Service
@Transactional
public class ProductMsgService{
	private Logger logger = Logger.getLogger(ProductMsgService.class);
	
	@Autowired
    private TmFixCodeMapper tmFixCodeMapper;
	
	@Autowired
    private TmTpProductGroupMapper productGroupMapper ;
	
	@Autowired
	private TmTpProductCategoryMapper tmTpProductCategoryMapper;
	/**
     * 搜索条件下拉列表
     * @author lyq
     * @date 2017年4月17日
     * @return
     * @throws Exception
     */
	public List<TmFixCode> queryTypeList(Integer codeType){
		TmFixCode fixCode = new TmFixCode();
    	fixCode.setCodeType(codeType);
    	List<TmFixCode> codeList = tmFixCodeMapper.select(fixCode);
        return codeList;
    	
	}
	/**
     * 获取产品规格
     * @author lyq
     * @date 2017年4月17日
     * @return
     * @throws Exception
     */
	public List<Map<String,Object>> getProductNorms(String inputSku){
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
    	TmTpProductGroup productGroup = new TmTpProductGroup();
    	productGroup.setInputSku(inputSku);
    	List<TmTpProductGroup> codeList = productGroupMapper.queryProductGroup(inputSku);
    	if(codeList!=null && codeList.size()>0){
    		for (TmTpProductGroup po : codeList) {
    			Map<String,Object> map = new HashMap<String,Object>();
				map.put("dim", po.getDim());
				map.put("saleName", po.getSaleName());
				productGroup.setDim(po.getDim());
				List<TmTpProductGroup> glist = productGroupMapper.select(productGroup);
				List<Map<String,Object>> grouplist = new ArrayList<Map<String,Object>>();
				for (TmTpProductGroup po1 : glist) {
					Map<String,Object> map1 = new HashMap<String,Object>();
					map1.put("imagePath", po1.getImagePath());
					map1.put("saleValue", po1.getSaleValue());
					String arr[] = po1.getSku().split(",");
					map1.put("skuIds", arr);
					grouplist.add(map1);
				}
				map.put("saleAttrList", grouplist);
				list.add(map);
				
			}
    	}
        return list;
    	
	}
	
	/***
	 * 查询所有商品分类
	 * 根据查询条件查出有效／无效／所有
	 * @param params
	 * @return
	 */
	public List<TmTpProductCategory> getProductCategorys(Map<String,Object> params){
		List<TmTpProductCategory> categoryList = tmTpProductCategoryMapper.queryProductCategorys(params);
		 return categoryList;
		
	}
	
}
	

